<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Pesquisar Usuário</h2>
        </ui:define>

        <ui:define name="body">
            <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />

            <p:panel styleClass="container_24 clearfix">
                <div class="buttonAction" style="float: right">
                    <p:button value="Adicionar" href="criarusuario.xhtml" icon="ui-icon-plusthick"
                              styleClass="ui-priority-primary"/>
                </div>
                <br/>
            </p:panel>

            <h:form id="secretariaForm" enctype="multipart/form-data">            
                <p:panel styleClass="container_24 clearfix">

                    <p:outputLabel value="Nome: " styleClass="grid_3"/>
                    <p:inputText styleClass="grid_20" value="#{managerPesquisarUsuario.usuario.nome}"/>
                    <div class="clear"/>
                    <p:outputLabel value="Login:" styleClass="grid_3"/>
                    <p:inputText styleClass="grid_20" value="#{managerPesquisarUsuario.usuario.login}"/>

                    <div class="buttonAction">
                        <p:commandButton id="bt_pesquisar" value="Pesquisar" icon="ui-icon-search"
                                         update="resultadoTable"
                                         actionListener="#{managerPesquisarUsuario.pesquisar()}"
                                         styleClass="ui-priority-primary" />
                        <p:commandButton id="limpar" value="Limpar" icon="ui-icon-close"
                                         update="@form"
                                         actionListener="#{managerPesquisarUsuario.init()}"/>
                    </div>

                </p:panel>

                <p:panel styleClass="container_24 clearfix">
                    <p:dataTable id="resultadoTable" var="item" value="#{managerPesquisarUsuario.dataModel}" 
                                 styleClass="grid_24" rowIndexVar="rowid"
                                 binding="#{managerPesquisarUsuario.searchResults}"
                                 rows="5" paginator="true" lazy="true"   
                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                 currentPageReportTemplate="{currentPage} de {totalPages}"
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro encontrado">

                        <f:facet name="header">
                            <p:outputLabel value="Resultados #{managerPesquisarUsuario.searchResults.rowCount eq 0 ? '' : '('.concat(managerPesquisarUsuario.searchResults.rowCount).concat(')')}" />
                        </f:facet>
                        <p:column headerText="Ação" width="100px;" > 
                            <p:button title="Visualizar" icon="ui-icon-zoomin"
                                      href="visualizarusuario.xhtml?usuario=#{item.id}"/>
                            <p:button title="Alterar" 
                                      rendered="#{item.id eq managerLayout.usuarioLogado.id}"
                                      href="alterarsenha.xhtml?usuario=#{item.id}"
                                      icon="ui-icon-unlocked"/>
                            <p:commandButton title="Excluir" rendered="#{item.id ne managerLayout.usuarioLogado.id}"
                                             oncomplete="dlg.show()" icon="ui-icon-trash">
                                <f:setPropertyActionListener target="#{managerPesquisarUsuario.usuarioExcluir}" value="#{item}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="Nome"> 
                            <p:outputLabel value="#{item.nome}"/>
                        </p:column>

                    </p:dataTable>
                </p:panel>

                <div class="buttonAction">
                    <p:button href="criarusuario.xhtml" value="Cancelar" icon="ui-icon-circle-close"/>
                </div>

                <p:dialog id="exclusaoDialog" header="Exclusão" widgetVar="dlg" closable="true"
                          appendToBody="true" closeOnEscape="true" modal="true" resizable="false" height="80">
                    <h:outputText value="Deseja excluir esse Usuário ?" /> <br/> 

                    <div class="buttonAction">
                        <p:commandButton value="Sim" update="@form" icon="ui-icon-check" onsuccess="dlg.hide()"
                                         actionListener="#{managerPesquisarUsuario.remover()}"/>
                        <p:commandButton value="Não" process="@this" onclick="dlg.hide()" icon="ui-icon-close" />
                    </div>

                </p:dialog>   

            </h:form>
        </ui:define>
    </ui:composition>
</html>
